/*duptest1.c*/
 #include<unistd.h>
 #include<fcntl.h>
 #include<stdio.h>
 #include<sys/types.h>
 void main()
 {
    int newfd,oldfd1,oldfd2,newfd2;
    oldfd1=open("a.txt",O_WRONLY);
    oldfd2=open("b.txt",O_WRONLY);
   if (oldfd1>0) printf("The oldfd1 file descriptor =%d\n",oldfd1);
   if (oldfd2>0) printf("The oldfd2 file descriptor =%d\n",oldfd2);
   newfd=dup(oldfd1);
   printf("The newfd file descriptor =%d\n",newfd);
   newfd2=dup2(oldfd1,newfd2);
   printf("The newfd2 file descriptor =%d\n",newfd2); 
 }
